const log = (type) => {
  return (target, name, descriptor) => {
    let method = descriptor.value; // 具体三个方法
    // descriptor对象原来的值如下
    // {
    //    value: specifiedFunction,
    //    enumerable: false,
    //    configurable: true,
    //    writable: true
    // };
    console.log(`target:${console.dir(target)},type:${type},name:${name},descriptor:${console.dir(descriptor)},`);
    target.eat()
    console.log(target.age);
    
    descriptor.value = (...args) => {
      let result;
      try {
        result = method.apply(target, args);
        console.log(`${type}: ${result}成功`)
      } catch (error) {
        console.log(`${type}: ${result}失败`)
      }
      return result;
    }
  }
}

class Man {
  constructor() {
    this.age = 19
  }

  @log('正在洗漱')
  wash() { return "洗漱" }

  @log('正在吃饭')
  eat() { return "吃饭" }

  @log('正在跑步')
  run() { return "跑步" }
}


let m = new Man();
console.log("———————————————————");
m.wash()
m.eat();
m.run();

/*
Man {}
target:undefined,type:正在洗漱,name:wash,descriptor:[object Object],
Man {}
target:undefined,type:正在吃饭,name:eat,descriptor:[object Object],
Man {}
target:undefined,type:正在跑步,name:run,descriptor:[object Object],
正在吃饭 吃饭 成功
———————————————————
正在洗漱 洗漱 成功
正在吃饭 吃饭 成功
正在跑步 跑步 成功
Ken-MacBook:Learn_js_decorator kim$ node "/Users/Ken/Learn_js_decorator/dist/decorator的应用场景.js"
Man {}
{
  value: [Function: wash],
  writable: true,
  enumerable: false,
  configurable: true
}
target:undefined,type:正在洗漱,name:wash,descriptor:undefined,
Man {}
{
  value: [Function: eat],
  writable: true,
  enumerable: false,
  configurable: true
}
target:undefined,type:正在吃饭,name:eat,descriptor:undefined,
Man {}
{
  value: [Function: run],
  writable: true,
  enumerable: false,
  configurable: true
}
target:undefined,type:正在跑步,name:run,descriptor:undefined,
正在吃饭 吃饭 成功
———————————————————
正在洗漱 洗漱 成功
正在吃饭 吃饭 成功
正在跑步 跑步 成功
*/